<template>
	<view class="toubu">
		<view class="tankuang" v-if="loadingShow==true || panduan_shows == true" @click="dianji()">
			<image v-if="state==0" src="/static/image/components/shouquan.png" class="tupian_login"></image>
								
			<view class="tankuang_content" v-if="state==0" style="height:480rpx">
				<view class="qianhuione_ziti thirty" style="margin-top:130rpx;margin-bottom:12rpx">为了提供给您更好的服务</view>
				<view class="qianhuione_ziti thirty">请在稍后提示框中点击“允许”</view>
				<button class="denglu_anniu" hover-class="none" @tap="getUserProfile">
					<view class="weixin_text" hover-class="none">我知道啦</view>
				</button>
				<view style="font-size:28rpx;color:#CBCFCE"  @click="publics.navigateTo('/view/public/login')">平台用户登录</view>
			</view>
			<view class="tankuang_content" v-else>
				
				<view class="heise_ziti font_bold" style="margin-top:80rpx;margin-bottom:64rpx;font-size:38rpx">注册会员</view>
				<image src="/static/image/components/lianjie.png" style="width:90rpx;height:90rpx;"></image>
				<view class="qianhui_ziti thirty" style="margin-top:52rpx;">授权微信申请使用您的手机号快速登录</view>
				<button class="denglu_anniu" hover-class="none" open-type="getPhoneNumber" @getphonenumber="getphone">
					<view class="weixin_text" hover-class="none">一键登录</view>
				</button>
				<view style="font-size:28rpx;color:#CBCFCE;margin-bottom:64rpx"  @click="publics.navigateTo('/view/public/login')">平台用户登录</view>
				
				<!-- <view style="width: calc(100% - 120rpx);position: absolute;bottom: 30rpx;left:60rpx;">
					<view class="tankuang_title">备婚优选提醒您</view>
					<view class="tankuang_titles">请授权微信登录</view>
					<button class="denglu_anniu" v-if="state==0" hover-class="none" @tap="getUserProfile">
						<view class="weixin_text" hover-class="none">微信授权登录</view>
					</button>
					
					<button class="denglu_anniu" v-else hover-class="none" open-type="getPhoneNumber" @getphonenumber="getphone">
						<view class="weixin_text" hover-class="none">手机号登录</view>
					</button>
					<view style="font-size:20rpx;text-align: center;" @click="publics.navigateTo('/view/public/login')">管理员登录</view>
				</view> -->
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				type: '', //弹框
				password: '',
				zhuangtai: '',
				loginRes: '',
				state:0,
				infoRes:'',
				denglu_xinxi:''
			}
		},
		props: {
			panduan_shows: {
				type: Boolean,
				default: false
			},
			lujing: {
				type: String,
				default: ""
			},
		},
		computed: {
			loadingShow() {
				console.log('1222222222222222')
				console.log(this.configure.login.state.requestLoading);
				return this.configure.login.state.requestLoading;
			}
		},
		onShow: function() {
			console.log('logoo Show')
		},
		watch:{
			
		},
		onLoad() {
			uni.getStorage({
				key: 'token',
				success: function(res) {
					console.log(212222222222222222222)
					console.log('获取token值', res.data.data)
				}
			})
		},
		methods: {
			dianji:function(){
				this.$emit('logintan', false);
			},
			ccc: function() {
				this.loadingShow = false
				console.log(this.loadingShow)
			},
			getUserProfile() {
				var that = this
				console.log('小程序')
				uni.login({
					provider: 'weixin',
					success: function(loginRes) {
						console.log(loginRes);
						that.loginRes = loginRes
						console.log(that.loginRes);
						console.log(6666666666)
					}
				});
				uni.getUserProfile({
					desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
					success: (infoRes) => {
						//业务逻辑
						console.log(22222222222)
						console.log(that.loginRes)
						console.log(infoRes)
						that.infoRes=infoRes;
						that.logoo(infoRes)
					},
					fail(res) {
						console.log(res)
						
					}
				})
			},
			logoo(infoRes){
				var that = this
				this.configure.ajax({
					url: 'register/wechatLogin',
					tishi: 1,
					zhuang:1,
					data: {
						code: that.loginRes.code,
						encryptedData: infoRes.encryptedData,
						iv: infoRes.iv,
						nums: infoRes.rawData
					},
					method: 'POST',
					success: function(res) {
						if(res.code==1){
							that.configure.login.commit("hide_login")
							uni.setStorageSync('token_token', res.data.token);
							uni.setStorageSync('userinfo',res.data);
							that.tiaohzuan()
						}else{
							if(res.code==2){
								that.state=1;
								that.denglu_xinxi=res.data;
								console.log(that.denglu_xinxi)
							}else{
								uni.showToast({
									title: res.msg,
									icon: "none"
								});
							}
							
						}
						
					}
				})
			},
			getphone(e){
				var that = this
				console.log(e)
				if (!e.detail.iv) {
					uni.showToast({
						title:'获取手机号失败',
						icon:'none'
					})
					return;
				}
				that.shoujihao(e.detail.code)
			},
			shoujihao(code){
				var that = this
				this.configure.ajax({
					url: 'register/wechatgettel',
					tishi: 1,
					zhuang:2,
					data: {
						code:code,
						opeanid:that.denglu_xinxi.openid,
					},
					method: 'GET',
					success: function(res) {
						console.log('接口请求')
						console.log(res)
						if(res.code==1){
							that.configure.login.commit("hide_login")
							uni.setStorageSync('token_token', res.data.token);
							uni.setStorageSync('userinfo',res.data);
							that.tiaohzuan()
						}else{
							uni.showToast({
								title: res.msg,
								icon: "none"
							});
							// that.tuxing()
						}
					}
				})
			},
			tiaohzuan(){
				var test_url;
				let routes = getCurrentPages();
				let curRoute = routes[routes.length - 1].$page
				uni.reLaunch({
					url: curRoute.fullPath
					// url: '../../pages/public/gongzhonghao'
				});
			}
		}
	}
</script>

<style>
	.tankuang {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		z-index: 10;
		background-color: rgba(0, 0, 0, 0.2);
		/* display: flex; */
		/* justify-content: center;
		align-items: center; */
		z-index: 3000;
	}

	.tankuang_content {
		width: 100%;
		overflow: hidden;
		margin: 0 auto;
		background-color: #FFFFFF;
		border-radius: 20rpx 20rpx 0rpx 0rpx;
		/* background: url("/static/image/components/logoo.png") no-repeat; */
		background-size: 100% 100%;
		position: fixed;
		bottom: 0px;
		text-align: center;
	}

	.tupian_login{
		width:180rpx;
		height:180rpx;
		position: fixed;
		bottom: 390rpx;
		z-index:6;
		left:calc( (100% - 180rpx ) / 2);
	}
	.denglu_anniu {
		width: 66.66%;
		height: 88rpx;
		line-height: 88rpx;
		margin: 0 auto;
		border-radius: 12rpx;
		margin-top: 30rpx;
		margin-bottom: 30rpx;
		text-align: center;
		background-color: #05C160;
		color: #fff;
		margin-top:60rpx;
		box-shadow: 0rpx 2rpx 12rpx rgba(5, 136, 96, 0.5)  !important;
	}

	button[type=default] {
		/* background-color: #FFFFFF; */
		/* border: 2upx solid rgba(220, 0, 0, 1); */
		padding: 0px !important;
	}

	uni-button:after {
		border: 0upx;
	}
	uni-button {
		padding-left: 0px !important;
	}
	button::after {
		display: none;
	}
</style>
